/**
 * 编辑分类
 * @date    2020-04-26 02:09:39
 * @Author  likai
 * @email   
 */
import React,{useState} from 'react'
import {Modal,Input,Form} from 'antd'
import md5 from 'md5'
import utils from '@utils'
const formItemLayout = {
  labelCol: {
    xs: {
      span: 24,
    },
    sm: {
      span: 4,
    },
  },
}
export default props=>{
	let [form] = Form.useForm()
	const onFinish = ()=>{
		form.validateFields()
		.then(res=>{
			utils.post('/api/user/changePassword',{
				newPassword:md5(res.newPassword),
				oldPassword:md5(res.oldPassword)
			}).then(res=>{
				if(res.errorCode==0){
					props.onOk()
				}
			})
		})
		.catch(err=>{})
	}
	return <Modal
	    title={'修改密码'}
	    visible={true}
	    onOk={onFinish}
	    onCancel={()=>{
	    	props.onCancel()
	    }}
	    okText="确认"
	    cancelText="取消"
	  >
	  	<Form form={form} {...formItemLayout}>
	  		<Form.Item
	        name="newPassword"
	        label="新密码"
	        rules={
	        	[{
	            required: true,
	            message: '请输入新密码',
	          }]
	        }
	      >
	        <Input placeholder='新密码' />
	      </Form.Item>
	      <Form.Item name="oldPassword" label="旧密码"
	        rules={
	        	[{
	            required: true,
	            message: '请输入旧密码',
	          }]
	        }
	      >
	        <Input placeholder='旧密码' />
	      </Form.Item>
	      
	  	</Form>
	  </Modal>
}
